package vip.xiaonuo.smzq.modular.user.controller;

import javax.annotation.Resource;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vip.xiaonuo.smzq.modular.user.entity.Org;
import vip.xiaonuo.smzq.modular.user.service.IOrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import vip.xiaonuo.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 组织
 *
 * @author sqq
 * @since 2024-04-22
 */
@Api(tags = "组织")
@RestController
@RequestMapping("/user/org")
@Validated
public class OrgController {

    @Resource
    private IOrgService iOrgService;

    /**
     * 添加组织
     */
    @ApiOperation("添加组织")
    @PostMapping("/add")
    public CommonResult<String> add(@RequestBody @Valid Org org) {
        iOrgService.save(org);
        return CommonResult.ok();
    }

    /**
     * 删除组织
     */
    @ApiOperation("删除组织")
    @PostMapping("/delete")
    public CommonResult<String> delete(@ApiParam(name = "pkid", value = "主键") @RequestParam String pkid) {
        iOrgService.removeById(pkid);
        return CommonResult.ok();
    }

    /**
     * 编辑组织
     */
    @ApiOperation("编辑组织")
    @PostMapping("/edit")
    public CommonResult<String> edit(@RequestBody @Valid Org org) {
        iOrgService.updateById(org);
        return CommonResult.ok();
    }

    /**
     * 组织分页查询
     */
    @ApiOperation("组织分页查询")
    @GetMapping("/list")
    public CommonResult<Page<Org>> page() {
        return CommonResult.data(iOrgService.page(new Org()));
    }
}
